<?php

namespace App\Http\Service\web;

class Siberian
{
    const EPOCH = 1479533469333;    //开始时间,固定一个小于当前时间的毫秒数
    const max12bit = 4095;
    const max41bit = 1099511627775;
//    会员卡密生成
    public static function siberian(){
        $time = floor(microtime(true) * 1000);
        $time -= self::EPOCH;
        $base = decbin(self::max41bit + $time);
        $str="abcdefghijkmnpqrstuvwxyzABCDEFGHIGKLMNPQRSTUVWXYZ".$time.$base;
        $codeLen='11';//设置生成的随机数个数
        return self::str_rand($str,$codeLen);
    }

    public static function str_rand($str,$codeLen): string
    {
        $rand="";
        for($i=0; $i<$codeLen-1; $i++){
            $rand .= $str[mt_rand(0, strlen($str)-1)];  //如：随机数为30  则：$str[30]
        }
        return $rand;
    }
}
